package part20;

import part20.annotation.UseCase;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author wcj
 * @Date 2021/6/6 15:43
 * @Version 1.0
 */
public class Part202 {

    /**
     * 注解处理器：即通过反射机制获取注解信息
     *
     * @param idList
     * @param type
     */
    public static void testUseCase(List<Integer> idList, Class<?> type) {
        for (Method method : type.getDeclaredMethods()) {
            UseCase annotation = method.getAnnotation(UseCase.class);
            if (annotation != null) {
                System.out.println("UseCase:" + annotation.id() + ",description:" + annotation.description());
                idList.remove(new Integer(annotation.id()));
            }
        }
        for (Integer integer : idList) {
            System.out.println("Warning:Missing use case-" + integer);
        }
    }

    public static void main(String[] args) {
        List<Integer> idList = new ArrayList<>();
        Collections.addAll(idList, 47, 48, 49, 50);
        testUseCase(idList, PasswordUtils.class);
    }
}
